<?php
/** @package    utility
 * @subpackage CalcValue
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class CalcValueActions extends sfActions
{
 public function executeIndex(sfWebRequest $request)
  {
    $this->forward('CalcValue', 'list');
  }
  
public function executeList()
{
	  $c = new Criteria();
	  $c->add(CalcValuePeer::STATUS, Constant::RECORD_STATUS_DELETED, Criteria::NOT_EQUAL);
	  $c->addAscendingOrderByColumn(CalcValuePeer::ID);
	  $this->calcvalues = CalcValuePeer::doSelect ($c);
} // - END - executeList 

public function executeAdd(sfWebRequest $request)
{
  
	if ($request->isMethod('Post'))
		{
		$calcvalue = new CalcValue();
		$calcvalue->setTitle($request->getParameter('title'));
		$calcvalue->setValue($request->getParameter('value'));
		$calcvalue->setStatus(Constant::RECORD_STATUS_ACTIVE);
		
		$calcvalue->save();
		$this->getUser()->setFlash('SUCCESS_MESSAGE', Constant::RECORD_ADDED_SUCCESSFULLY);
		$this->redirect ('CalcValue/list');
		} //end if
 
  } // - END - executeAdd

public function executeEdit (sfWebRequest $request)
	{
		if ($request->isMethod('Post'))
		{
			$calcvalue = CalcValuePeer::retrieveByPk($this->getRequestParameter('id'));
			$calcvalue->setValue($request->getParameter('value'));
			
			//Save object to database
			if($calcvalue->save())
			{
				$this->getUser()->setFlash('SUCCESS_MESSAGE', Constant::RECORD_EDITED_SUCCESSFULLY);
				$this->redirect ('CalcValue/list');
			}
			else
			{
				$this->getUser()->setFlash('ERROR_MESSAGE', Constant::DB_ERROR);
				$this->redirect('CalcValue/edit?id='.Utility::EncryptQueryString($request->getParameter('id')));
			}
		}

		else
		{
			$this->calcvalue = CalcValuePeer::retrieveByPk(Utility::DecryptQueryString($request->getParameter('id')));
			
		}
	} //- END - executeEdit

public function executeDelete (sfWebRequest $request)
	{
		$calcvalue = CalcValuePeer::retrieveByPk(Utility::DecryptQueryString($request->getParameter('id')));

		if($calcvalue)
		{
			$calcvalue->setStatus(Constant::RECORD_STATUS_DELETED);
			if(	$calcvalue->save())
			$this->getUser()->setFlash('SUCCESS_MESSAGE', Constant::RECORD_STATUS_DELETED_SUCCESSFULLY);
			else
			$this->getUser()->setFlash('ERROR_MESSAGE', Constant::DB_ERROR);
		}
		else
		{
			$this->getUser()->setFlash('ERROR_MESSAGE', Constant::INVALID_REQUEST);
		}
	
		$this->redirect ('CalcValue/list');

	} //- END - executeDelete
}
